<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Hero War: main.cpp</title>
<link href="../../tabs.css" rel="stylesheet" type="text/css">
<link href="../../doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Généré par Doxygen 1.5.8 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="../../index.html"><span>Page&nbsp;principale</span></a></li>
      <li><a href="../../namespaces.html"><span>Espaces&nbsp;de&nbsp;nommage</span></a></li>
      <li><a href="../../annotated.html"><span>Classes</span></a></li>
      <li><a href="../../files.html"><span>Fichiers</span></a></li>
      <li><a href="../../examples.html"><span>Exemples</span></a></li>
    </ul>
  </div>
</div>
<div class="contents">
<h1>main.cpp</h1>Un exemple vite fait que j'utilisais pour tester le tout.<p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include &lt;iostream&gt;</span>
<span class="preprocessor">#include &lt;fstream&gt;</span>
<span class="preprocessor">#include &lt;sstream&gt;</span>
<span class="preprocessor">#include &lt;string&gt;</span>

<span class="preprocessor">#include &lt;gfx/gfx.h&gt;</span>

<span class="keyword">using namespace </span>std;
<span class="keyword">using namespace </span>gfx;

<span class="keyword">const</span> <span class="keywordtype">float</span> SPEED=0.5f;

<span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>* args[])
{
        <span class="comment">// Create the main rendering window</span>
        sf::RenderWindow App(sf::VideoMode(1280, 1024, 32), <span class="stringliteral">"Hero War 0.01b"</span>);
        <span class="comment">//App.UseVerticalSync(false);</span>

        <span class="comment">//Cree la surface servant d'ecran</span>
        <a name="_a0"></a><a class="code" href="../../d2/d2e/classgfx_1_1_layer.html" title="Petite classe simple qui gère le système de couche de drawable. Elle a la même...">Layer</a> screen;

        <span class="comment">//Charge une map</span>
        <span class="comment">//1. Charge le tileset</span>
        sf::Image imgTiles;
        imgTiles.LoadFromFile(<span class="stringliteral">"C:/Documents and Settings/israhal17/Mes documents/Visual Studio 2005/Projects/HeroWar/debug/tileset.png"</span>);
        imgTiles.SetSmooth(<span class="keyword">true</span>);

        <a class="code" href="../../d0/d1c/namespacegfx.html#35f773ecd26db8607f55fc71561889df" title="Conteneur avec des rect qui associe chaque numéro de tile à une sous image dans...">RectTileSet</a> rectTileSet;

        rectTileSet[0]=sf::IntRect(192,0,256,64);
        rectTileSet[1]=sf::IntRect(0,0,64,64);
        rectTileSet[2]=sf::IntRect(192,0,320,64);
        rectTileSet[3]=sf::IntRect(192,64,256,128);
        rectTileSet[4]=sf::IntRect(64,64,128,128);
        rectTileSet[5]=sf::IntRect(0,64,64,128);

        <span class="comment">//2.Cree la map et sa matrice</span>
        <a name="_a1"></a><a class="code" href="../../dc/dcf/classgfx_1_1_map.html" title="Classes qui gère la matrices d&amp;#39;une map.">Map</a> map(91,78);

        ifstream fileMap(<span class="stringliteral">"C:/Documents and Settings/israhal17/Mes documents/Visual Studio 2005/Projects/HeroWar/debug/grass.map"</span>);
        <span class="keywordflow">if</span>(!fileMap.good())
                cout &lt;&lt; <span class="stringliteral">"Impossible de charge la map"</span> &lt;&lt; endl;

        <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0;i&lt;map.<a name="a2"></a><a class="code" href="../../dc/dcf/classgfx_1_1_map.html#5f9ff7f55c4f5ec6015b5e52ec2d0df8" title="Retourne la hauteur de la map.">getHeight</a>();i++)
        {
                <span class="keywordflow">for</span>(<span class="keywordtype">int</span> y=0;y&lt;map.<a name="a3"></a><a class="code" href="../../dc/dcf/classgfx_1_1_map.html#8262e32ad03e463559bb1b4d7b8fa43a" title="Retourne la largeur de la map.">getWidth</a>();y++)
                {
                        <span class="keywordtype">int</span> type=0;
                        fileMap &gt;&gt; type;
                        map[y][i]=type;
                }
        }


        <a name="_a4"></a><a class="code" href="../../d3/db5/classgfx_1_1_d_l_map.html" title="Affiche une map de tile de manière optimisé avec les Display List de openGL à...">DLMap</a> forestMap1(map.<a name="a5"></a><a class="code" href="../../dc/dcf/classgfx_1_1_map.html#36979e345931a619760cdae922b0defc">getSubMap</a>(sf::IntRect(0,0,40,40)),&amp;imgTiles,rectTileSet,sf::FloatRect(0,0,64.0,64.0));
        <a class="code" href="../../d3/db5/classgfx_1_1_d_l_map.html" title="Affiche une map de tile de manière optimisé avec les Display List de openGL à...">DLMap</a> forestMap2(map.<a class="code" href="../../dc/dcf/classgfx_1_1_map.html#36979e345931a619760cdae922b0defc">getSubMap</a>(sf::IntRect(40,0,80,40)),&amp;imgTiles,rectTileSet,sf::FloatRect(0,0,64.0,64.0));
        <a class="code" href="../../d3/db5/classgfx_1_1_d_l_map.html" title="Affiche une map de tile de manière optimisé avec les Display List de openGL à...">DLMap</a> forestMap3(map.<a class="code" href="../../dc/dcf/classgfx_1_1_map.html#36979e345931a619760cdae922b0defc">getSubMap</a>(sf::IntRect(0,40,40,80)),&amp;imgTiles,rectTileSet,sf::FloatRect(0,0,64.0,64.0));
        <a class="code" href="../../d3/db5/classgfx_1_1_d_l_map.html" title="Affiche une map de tile de manière optimisé avec les Display List de openGL à...">DLMap</a> forestMap4(map.<a class="code" href="../../dc/dcf/classgfx_1_1_map.html#36979e345931a619760cdae922b0defc">getSubMap</a>(sf::IntRect(40,40,80,80)),&amp;imgTiles,rectTileSet,sf::FloatRect(0,0,64.0,64.0));
        <a class="code" href="../../d3/db5/classgfx_1_1_d_l_map.html" title="Affiche une map de tile de manière optimisé avec les Display List de openGL à...">DLMap</a> forestMap5(map.<a class="code" href="../../dc/dcf/classgfx_1_1_map.html#36979e345931a619760cdae922b0defc">getSubMap</a>(sf::IntRect(80,0,100,80)),&amp;imgTiles,rectTileSet,sf::FloatRect(0,0,64.0,64.0));

        <a class="code" href="../../d0/d1c/namespacegfx.html#d36691b69ef221131fbe25be4de15885" title="Tileset qui associe un nombre dans la matrice de la map à un sf::Drawable.">TileSet</a> tileSet;
        tileSet[1]=&amp;forestMap1;
        tileSet[2]=&amp;forestMap2;
        tileSet[3]=&amp;forestMap3;
        tileSet[4]=&amp;forestMap4;
        tileSet[5]=&amp;forestMap5;

        <a name="_a6"></a><a class="code" href="../../d2/dc0/classgfx_1_1_map_layer.html" title="Map qui affiche dynamiquement des drawable un par un selon le viewport.">MapLayer</a> forestMap(3,2,&amp;tileSet,sf::IntRect(0,0,64*20,64*20));
        forestMap[0][0]=1;
        forestMap[1][0]=2;
        forestMap[0][1]=3;
        forestMap[1][1]=4;
        forestMap[2][0]=5;

        <span class="comment">//3. Cree le sprite du Hero</span>
        sf::Image imgZelda;
        imgZelda.LoadFromFile(<span class="stringliteral">"C:/Documents and Settings/israhal17/Mes documents/Visual Studio 2005/Projects/HeroWar/debug/zelda_sprite.png"</span>);
        imgZelda.SetSmooth(<span class="keyword">false</span>);
        imgZelda.CreateMaskFromColor(sf::Color(255,0,255));

        <a name="_a7"></a><a class="code" href="../../d8/d31/classgfx_1_1_img_anim.html" title="Comme Anim à la diférence près que la classe utilise une image avec tout les sprites...">ImgAnim</a> zelda(imgZelda,8,4);
        zelda.Scale(4.f,4.f);
        zelda.<a name="a8"></a><a class="code" href="../../df/d6a/classgfx_1_1_anim.html#bdbe43f27fcda4c08f24d9d8873072ef" title="Définis le délais en seconde entre chaque frame.">setDelay</a>(.1f);

        sf::String fps;
        <span class="keywordtype">float</span> Framerate;
        <span class="keywordtype">string</span> fpsStr;

        sf::View view(sf::FloatRect(400, 300, 400, 300));
        view.SetFromRect(sf::FloatRect(0, 0, 1280, 1024));
        App.SetView(view);

    screen.push_back(&amp;forestMap);
    screen.push_back(&amp;zelda);


    <span class="keywordflow">while</span> (App.IsOpened())
    {
                Framerate = 1.f / App.GetFrameTime();
                std::ostringstream oss;
                oss &lt;&lt; Framerate;
                fpsStr = <span class="stringliteral">"FPS: "</span> + oss.str();

                fps.SetText(fpsStr);
                fps.SetScale(view.GetHalfSize().x/640,view.GetHalfSize().x/640);


        <span class="comment">// Process events</span>
        sf::Event Event;
        <span class="keywordflow">while</span> (App.GetEvent(Event))
        {
            <span class="comment">// Close window : exit</span>
            <span class="keywordflow">if</span> (Event.Type == sf::Event::Closed)
                App.Close();
        }


                <span class="keyword">const</span> sf::Input&amp; Input = App.GetInput();
                <span class="keywordflow">if</span>(Input.IsKeyDown(sf::Key::Left) )
                {
                        zelda.Move(-SPEED,0.f);
                        zelda.<a name="a9"></a><a class="code" href="../../d8/d31/classgfx_1_1_img_anim.html#6945d2f1b47a330401704e178b6b6b08" title="Définis la ligne animé courante.">setAnimRow</a>(3);
                        zelda.<a name="a10"></a><a class="code" href="../../df/d6a/classgfx_1_1_anim.html#79dd5ff2d9497e08e08c7c945b1ccdcd" title="Joue l&amp;#39;animation.">play</a>();
                }

                <span class="keywordflow">if</span>(Input.IsKeyDown(sf::Key::Right) )
                {
                        zelda.Move(SPEED,0.f);
                        zelda.<a class="code" href="../../d8/d31/classgfx_1_1_img_anim.html#6945d2f1b47a330401704e178b6b6b08" title="Définis la ligne animé courante.">setAnimRow</a>(1);
                        zelda.<a class="code" href="../../df/d6a/classgfx_1_1_anim.html#79dd5ff2d9497e08e08c7c945b1ccdcd" title="Joue l&amp;#39;animation.">play</a>();
                }
                <span class="keywordflow">if</span>(Input.IsKeyDown(sf::Key::Up))
                {
                        zelda.Move(0.f,-SPEED);
                        zelda.<a class="code" href="../../d8/d31/classgfx_1_1_img_anim.html#6945d2f1b47a330401704e178b6b6b08" title="Définis la ligne animé courante.">setAnimRow</a>(2);
                        zelda.<a class="code" href="../../df/d6a/classgfx_1_1_anim.html#79dd5ff2d9497e08e08c7c945b1ccdcd" title="Joue l&amp;#39;animation.">play</a>();
                }
                <span class="keywordflow">if</span>(Input.IsKeyDown(sf::Key::Down))
                {
                        zelda.Move(0.f,SPEED);
                        zelda.<a class="code" href="../../d8/d31/classgfx_1_1_img_anim.html#6945d2f1b47a330401704e178b6b6b08" title="Définis la ligne animé courante.">setAnimRow</a>(0);
                        zelda.<a class="code" href="../../df/d6a/classgfx_1_1_anim.html#79dd5ff2d9497e08e08c7c945b1ccdcd" title="Joue l&amp;#39;animation.">play</a>();
                }
                <span class="keywordflow">if</span>(!Input.IsKeyDown(sf::Key::Down) &amp;&amp;
                        !Input.IsKeyDown(sf::Key::Up) &amp;&amp;
                        !Input.IsKeyDown(sf::Key::Right) &amp;&amp;
                        !Input.IsKeyDown(sf::Key::Left))
                {
                        zelda.<a name="a11"></a><a class="code" href="../../df/d6a/classgfx_1_1_anim.html#304a61788dc80d57777301a533652d03" title="Arrete l&amp;#39;animation et remet le compteur à zéro.">stop</a>();
                }
                <span class="keywordflow">if</span>(Input.IsKeyDown(sf::Key::A))
                {
                        view.Zoom(01.01f);
                }
                <span class="keywordflow">else</span> <span class="keywordflow">if</span>(Input.IsKeyDown(sf::Key::S))
                {
                        view.Zoom(0.99f);
                }
                <span class="keywordflow">else</span> <span class="keywordflow">if</span>(Input.IsKeyDown(sf::Key::Q))
                {
                        zelda.<a name="a12"></a><a class="code" href="../../df/d6a/classgfx_1_1_anim.html#33c2dbc7c2544550b23b93efdbd73284" title="Met l&amp;#39;animation en pause et laisse le compteur où il en est.">pause</a>();
                }
                <span class="keywordflow">else</span> <span class="keywordflow">if</span>(Input.IsKeyDown(sf::Key::W))
                {
                        zelda.<a class="code" href="../../df/d6a/classgfx_1_1_anim.html#79dd5ff2d9497e08e08c7c945b1ccdcd" title="Joue l&amp;#39;animation.">play</a>();
                }

                <span class="keywordflow">if</span>(Input.IsKeyDown(sf::Key::E))
                {
                        zelda.<a class="code" href="../../df/d6a/classgfx_1_1_anim.html#304a61788dc80d57777301a533652d03" title="Arrete l&amp;#39;animation et remet le compteur à zéro.">stop</a>();
                }
                <span class="keywordflow">if</span>(Input.IsKeyDown(sf::Key::R))
                {
                        zelda.Scale(0.999f,0.999f);
                }
                <span class="keywordflow">if</span>(Input.IsKeyDown(sf::Key::T))
                {
                        zelda.Scale(1.001f,1.001f);
                }
                view.SetCenter(zelda.GetPosition());

                fps.SetPosition(view.GetRect().Left,view.GetRect().Top);

                forestMap.<a name="a13"></a><a class="code" href="../../d2/dc0/classgfx_1_1_map_layer.html#1f7740fe56fe3aa582a06bc5f193f164" title="Définie la zone à afficher (viewport).">setSubRect</a>(view.GetRect());

                App.Clear();
                App.Draw(screen);
                App.Draw(fps);
                App.Display();
    }

        <span class="keywordflow">return</span> 0;
}
</pre></div> </div>
<hr size="1"><address style="text-align: right;"><small>Généré le Wed Feb 4 02:28:38 2009 pour Hero War par&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="../../doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address>
</body>
</html>
